﻿<%@ Page Language="C#" MasterPageFile="~/master/admin.master" AutoEventWireup="true"
    CodeFile="sales-ccsuccess.aspx.cs" Inherits="admin_sales_ccsuccess" Title="Untitled Page" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register Namespace="ECommerce.Library.Web" TagPrefix="ucc" %>
<%@ Register Src="~/controls/wucAdminValidator.ascx" TagName="AdminValidator" TagPrefix="wuc" %>
<asp:Content ID="cntMiddleContent" ContentPlaceHolderID="cphMiddleContent" runat="Server">
    <script type="text/javascript">

        var OrderCode_Renderer = function (value, p, record, rowIndex) {

            var categoryUrl;
            if (record.data.IsMultipleShip) {
                categoryUrl = String.format("shipping-list.aspx?oid={0}", record.data.OrderId);
                categoryUrl = String.format("<a href=\"{0}\" class=\"leftlink\">{1}</a>", categoryUrl, "13-P" +value);
            }
            else {
                categoryUrl = String.format("<%= Page.ResolveUrl(AutoGear.BLL.CustomSiteMap.InvoicePrintPage) %>?print=0&oid={0}", record.data.OrderCode);
                categoryUrl = String.format("<a href=\"{0}\" class=\"leftlink\" target=\"_blank\">{1}</a>", categoryUrl, "13-P" +value);
            }

            return categoryUrl;
        };

        var SPName_Renderer = function (value, p, record, rowIndex) {
            var categoryUrl;
            categoryUrl = String.format("sales-person-edit.aspx?cuid={0}", record.data.SPId);
            categoryUrl = String.format("<a href=\"{0}\" class=\"leftlink\" target=\"_blank\">{1}</a>", categoryUrl, record.data.SPName);
            return categoryUrl;
        };
        var Invoice_Renderer = function (value, p, record, rowIndex) {
            var categoryUrl;
            var urltext;
            urltext = String.format("<a class=\"leftlink\" target=\"_blank\">{1}</a>", categoryUrl, "");
            return urltext;
        };

        function ShowDetails(type,cardNo,expDt,secCode) {
            winDetails.show();
            <%= txtType.ClientID %>.setText(type);
            <%= txtCardNo.ClientID %>.setText(cardNo);
            <%= txtExpDate.ClientID %>.setText(expDt);
        }

        var CCInfo_Renderer = function (value, p, record, rowIndex) {
                
               return "<a class=\"leftlink\" onclick=\"ShowDetails('"+record.data.CardType+"','"+record.data.CardNumber+"','"+record.data.ExpireDate+"','"+record.data.CardCode+"')\" title='Payment Details' ><img src='../App_Style/images/payment.png' /></a>";
        }

        var Date_Renderer = function (value) {
            var dt = new Date(value);
            return dt.format('m/d/Y');
        }

        var OrderTrackNumber_Renderer = function (value, p, record, rowIndex) {
            if (value == "")
                return String.format("<a href='#' onclick='BeginEditing({0})' class='leftlink'>Modify Shipping</a>", rowIndex);
            else
                return "Tracking# " + value;
        };

        var CustomerName_Renderer = function (value, p, record, rowIndex) {
            return record.data.FirstName + " " + record.data.LastName;
        }

        var Address_Renderer = function (value, p, record, rowIndex) {
            return record.data.BillingAddressLine1 + ", " + record.data.City + ", " + record.data.State + ", " + record.data.Zip;
        }

        var BeginEditing = function (rowIndex) {
            if (categoryGrid != null) {
                var grid = categoryGrid;
                grid.getRowEditor().stopEditing();
                grid.getView().refresh();
                grid.getSelectionModel().selectRow(rowIndex);
                grid.getRowEditor().startEditing(rowIndex);
            }
        };

        var CommandHandler = function (command, rowIndex, grid) {
            //showObj(grid);

             grid.getRowEditor().stopEditing();
                grid.getView().refresh();
                grid.getSelectionModel().selectRow(rowIndex);
                grid.getRowEditor().startEditing(rowIndex);
        }

        var afterEdit = function (e) {

            e.grid.stopEditing();
            var trackingNumber = $("#<%= txtTrackingNumber.ClientID %>").val();
            //alert(trackingNumber);

            // Call DirectMethod
            Polana.WebService.UpdateOrder(e.record.data.OrderId, trackingNumber);
        };

        var categoryGrid;

        var deleteOrders = function () {
            if (categoryGrid != null) {
                categoryGrid.getRowEditor().stopEditing();

                var s = categoryGrid.getSelectionModel().getSelections();
                if (s.length > 0) {

                    if (confirm("Are you sure you want to delete these orders?")) {

                        var ids = "";

                        for (var i = 0, r; r = s[i]; i++) {
                            ids = ids + " " + r.data.OrderId;
                        }

                        // Call DirectMethod
                        Polana.WebService.DeleteOrders(ids);
                    }
                }
            }
        }


        var QuickOrders = function () {
            if (categoryGrid != null) {
                // Call DirectMethod
                Polana.WebService.QuickOrders();
            }
        }
        var PrintFilter = function () {
            if (categoryGrid != null) {
                // Call DirectMethod
                Polana.WebService.PrintFilter();
            }
        }

        var ShippedFilter = function () {
            if (categoryGrid != null) {
                // Call DirectMethod
                Polana.WebService.ShippedFilter();
            }
        }
        var unprocessedFilter = function () {
            if (categoryGrid != null) {
                // Call DirectMethod
                Polana.WebService.UnprocessedFilter();
            }
        }
        var giftMessage = function () {
            if (categoryGrid != null) {
                // Call DirectMethod
                Polana.WebService.GiftMessage();
            }
        }

        var printOrders = function () {
            if (categoryGrid != null) {
                categoryGrid.getRowEditor().stopEditing();

                var s = categoryGrid.getSelectionModel().getSelections();
                if (s.length > 0) {

                    if (confirm("Are you sure you want to quick print these orders?")) {

                        var ids = "";

                        for (var i = 0, r; r = s[i]; i++) {
                            ids = ids + " " + r.data.OrderCode;
                        }

                        // Call DirectMethod
                        Polana.WebService.PrintOrders(ids);
                    }
                }
            }
        }

        var searchOrder = function (grid) {
            Polana.WebService.SearchOrder();
        }

        var winDetails;
        var onDocumentReady = function (grid, winDet) {
            categoryGrid = grid;
            winDetails = winDet;
        }

        function setRowColor(record) {
            if (record.data.OrderTrackNumber.toString() == 1) // or some value
            {
                return 'green';
            }
            if (record.data.PrintNo > 0) // or some value
            {
                return 'red';
            }
        }
    </script>
    <style type="text/css">
        .x-form-text
        {
            height: 16px !important;
            width: 100px;
        }
        .red
        {
            background: #EFC9C9;
            color: Black;
        }
        .green
        {
            background: #E1F7EC;
            color: Black;
        }
    </style>
    <ext:ResourceManager ID="ScriptManager1" runat="server" Theme="Gray">
        <Listeners>
            <DocumentReady Fn="onDocumentReady(#{GridPanel1},#{winDetails})" />
             
        </Listeners>
    </ext:ResourceManager>
    <ext:Store ID="Store1" runat="server" RemoteSort="true" OnRefreshData="Store1_RefreshData">
        <AutoLoadParams>
            <ext:Parameter Name="sort" Value="OrderId desc" Mode="Value" />
            <ext:Parameter Name="start" Value="0" Mode="Raw" />
            <ext:Parameter Name="limit" Value="100" Mode="Raw" />
        </AutoLoadParams>
        <Proxy>
            <ext:PageProxy />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="OrderId">
                <Fields>
                    <ext:RecordField Name="OrderId" />
                    <ext:RecordField Name="OrderCode" ServerMapping="OrderNumber" />
                    <ext:RecordField Name="CreateDate" ServerMapping="OrderDate" Type="Date" />
                    <ext:RecordField Name="FirstName" ServerMapping="BillingAddress.FirstName" />
                    <ext:RecordField Name="LastName" ServerMapping="BillingAddress.LastName" />
                    <ext:RecordField Name="EmailAddress" ServerMapping="BillingAddress.EmailAddress" />
                    <ext:RecordField Name="BillingAddressLine1" ServerMapping="BillingAddress.AddressLine1" />
                    <ext:RecordField Name="City" ServerMapping="BillingAddress.City" />
                    <ext:RecordField Name="State" ServerMapping="BillingAddress.AddressState" />
                    <ext:RecordField Name="Zip" ServerMapping="BillingAddress.ZipCode" />
                    <ext:RecordField Name="OrderPrice" ServerMapping="OrderAmount" />
                     <ext:RecordField Name="TotalAmount" ServerMapping="TotalAmount"  />
                    <ext:RecordField Name="PaymentType" ServerMapping="PaymentType" />
                    <ext:RecordField Name="IsMultipleShip" ServerMapping="IsMultipleShip" />
                    <ext:RecordField Name="OrderTrackNumber" />
                    <ext:RecordField Name="GIftCardMessage" />
                    <ext:RecordField Name="PrintNo">
                    </ext:RecordField>
                    <ext:RecordField Name="SPName" ServerMapping="SPName">
                    </ext:RecordField>
                    <ext:RecordField Name="SPId">
                    </ext:RecordField>
                    <ext:RecordField Name="ConfirmationNumber" ServerMapping="OfficeUse"></ext:RecordField>

                    <ext:RecordField Name="CardType" ServerMapping="CreditCard.CardType" />
                    <ext:RecordField Name="CardNumber" ServerMapping="CreditCard.CardNumber" />
                    <ext:RecordField Name="CardCode" ServerMapping="CreditCard.CardCode" />
                    <ext:RecordField Name="ExpireDate" ServerMapping="CreditCard.ExpireDate" />
                    <ext:RecordField Name="Freight" ServerMapping="ProductShipping.ProductShippingCost"></ext:RecordField>
                    <ext:RecordField Name="Tax" ServerMapping="ProductTax.Tax"></ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
        <%--  <Listeners>
                <Load Fn="selectRecords" Delay="10" />
            </Listeners>--%>
    </ext:Store>
    <div class="admin-function-top inline">
        <ucc:ResponseMessage ID="uccResponseMessage" runat="server"></ucc:ResponseMessage>
        <ext:Toolbar ID="Toolbar1" runat="server" AutoScroll="true">
            <Items>
                <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
              <%--  <ext:Button ID="btnToolbarPrint" runat="server" Text="Print Filter" Icon="Accept">
                    <Listeners>
                        <Click Handler="PrintFilter();" />
                    </Listeners>
                </ext:Button>
                <ext:Button ID="btnToolbarShipped" runat="server" Text="Shipped Filter" Icon="Accept">
                    <Listeners>
                        <Click Handler="ShippedFilter();" />
                    </Listeners>
                </ext:Button>--%>
                <ext:Button ID="btnToolbarunprocessed" runat="server" Text="Unprocessed" Icon="Accept">
                    <Listeners>
                        <Click Handler="unprocessedFilter();" />
                    </Listeners>
                </ext:Button>
               <%-- <ext:Button ID="btnToolbarQuickInvoice" runat="server" Text="Gift Invoice" Icon="Accept">
                    <Listeners>
                        <Click Handler="giftMessage();" />
                    </Listeners>
                </ext:Button>
                <ext:Button ID="btnToolbarQuickPrint" runat="server" Text="Quick Print" Icon="ApplicationViewIcons">
                    <Listeners>
                        <Click Handler="printOrders();" />
                    </Listeners>
                </ext:Button>--%>
                <ext:Button ID="btnToolbarDelete" runat="server" Text="Delete" Icon="Delete">
                    <Listeners>
                        <Click Handler="deleteOrders();" />
                    </Listeners>
                </ext:Button>
            </Items>
        </ext:Toolbar>
        <ext:GridPanel ID="GridPanel1" runat="server" EnableViewState="true" AutoHeight="true"
            StoreID="Store1">
            <ColumnModel>
                <Columns>
                    <ext:Column Header="Order #" Width="20" DataIndex="OrderCode">
                        <Renderer Fn="OrderCode_Renderer" />
                    </ext:Column>
                    <ext:Column Header="Date" Width="25" DataIndex="CreateDate" Align="Right">
                        <Renderer Fn="Date_Renderer" />
                    </ext:Column>
                    <ext:Column Header="Name" DataIndex="FirstName" Width="50">
                        <Renderer Fn="CustomerName_Renderer" />
                    </ext:Column>
                    <ext:Column Header="Email" DataIndex="EmailAddress" Width="65">
                    </ext:Column>
                    <ext:Column Header="Address" DataIndex="BillingAddressLine1" Width="85">
                        <Renderer Fn="Address_Renderer" />
                    </ext:Column>
                    <ext:Column Header="Net Cost" DataIndex="Total Price" Width="30" Align="Right">
                        <Renderer Format="UsMoney" />
                    </ext:Column>
                 <%--    <ext:Column Header="Freight" DataIndex="Freight" Width="30" Align="Right">
                        <Renderer Format="UsMoney" />
                    </ext:Column>
                     <ext:Column Header="Tax" DataIndex="Tax" Width="30" Align="Right">
                        <Renderer Format="UsMoney" />
                    </ext:Column>--%>
                    <ext:Column Header="Payment Method" DataIndex="PaymentType" Width="40" Align="Center">
                    </ext:Column>
                    <ext:Column Header="Confirmation Number" DataIndex="ConfirmationNumber" Width="40" Align="Right"></ext:Column>
                    <ext:Column DataIndex="OrderTrackNumber" Sortable="false" Align="Center" Width="50">
                        <Renderer Fn="OrderTrackNumber_Renderer" />
                        <Editor>
                            <ext:TextField ID="txtTrackingNumber" runat="server" EmptyText="Tracking Number" />
                        </Editor>
                    </ext:Column>
               <%--     <ext:Column Header="Sales" Width="20" DataIndex="SPName">
                        <Renderer Fn="SPName_Renderer" />
                    </ext:Column>--%>
                   <%-- <ext:Column Header="Print" Fixed="true" Sortable="true" ColumnID="label" MenuDisabled="true"
                        Width="80" DataIndex="GIftCardMessage" Align="Right">
                        <Renderer Fn="Invoice_Renderer" />
                    </ext:Column>--%>
                    <ext:Column Header="PritnNo" DataIndex="PrintNo" Width="50" Hidden="true">
                    </ext:Column>
                      <ext:Column Header="" Width="20" DataIndex="OrderId">
                        <Renderer Fn="CCInfo_Renderer" />                        
                    </ext:Column>
                </Columns>
            </ColumnModel>
            <TopBar>
                <ext:Toolbar ID="SearchToolbar2" runat="server" AutoScroll="true">
                    <Items>
                        <ext:TextField ID="txtOrderNo" runat="server" EmptyText="Order#" EnableKeyEvents="true"
                            Width="100">
                            <Listeners>
                                <KeyPress Handler="if(e.getKey() == Ext.EventObject.ENTER){e.preventDefault(); searchOrder(#{GridPanel1})}" />
                            </Listeners>
                        </ext:TextField>
                        <ext:ToolbarSpacer ID="ToolbarSpacer7" runat="server" Width="2px" />
                
                        <ext:DateField ID="txtDateFrom" runat="server" EmptyText="Date From" EnableKeyEvents="true"
                            Width="100">
                            <Listeners>
                                <KeyPress Handler="if(e.getKey() == Ext.EventObject.ENTER){e.preventDefault(); searchOrder(#{GridPanel1})}" />
                            </Listeners>
                        </ext:DateField>
                        <ext:ToolbarSpacer ID="ToolbarSpacer1" runat="server" Width="2px" />
                        <ext:DateField ID="txtDateTo" runat="server" EmptyText="Date To" EnableKeyEvents="true"
                            Width="100">
                            <Listeners>
                                <KeyPress Handler="if(e.getKey() == Ext.EventObject.ENTER){e.preventDefault(); searchOrder(#{GridPanel1})}" />
                            </Listeners>
                        </ext:DateField>
                        <ext:ToolbarSpacer ID="ToolbarSpacer2" runat="server" Width="2px" />
                        <ext:NumberField ID="txtPriceFrom" runat="server" DecimalPrecision="2" EmptyText="Price From"
                            EnableKeyEvents="true" Width="80">
                            <Listeners>
                                <KeyPress Handler="if(e.getKey() == Ext.EventObject.ENTER){e.preventDefault(); searchOrder(#{GridPanel1})}" />
                            </Listeners>
                        </ext:NumberField>
                        <ext:ToolbarSpacer ID="ToolbarSpacer3" runat="server" Width="2px" />
                        <ext:NumberField ID="txtPriceTo" runat="server" EmptyText="Price To" EnableKeyEvents="true"
                            Width="80">
                            <Listeners>
                                <KeyPress Handler="if(e.getKey() == Ext.EventObject.ENTER){e.preventDefault(); searchOrder(#{GridPanel1})}" />
                            </Listeners>
                        </ext:NumberField>
                        <ext:ToolbarSpacer ID="ToolbarSpacer4" runat="server" Width="2px" />
                        <ext:TextField ID="txtFirstName" runat="server" EmptyText="First Name" EnableKeyEvents="true"
                            Width="100">
                            <Listeners>
                                <KeyPress Handler="if(e.getKey() == Ext.EventObject.ENTER){e.preventDefault(); searchOrder(#{GridPanel1})}" />
                            </Listeners>
                        </ext:TextField>
                        <ext:ToolbarSpacer ID="ToolbarSpacer5" runat="server" Width="2px" />
                        <ext:TextField ID="txtLastName" runat="server" EmptyText="Last Name" EnableKeyEvents="true"
                            Width="100">
                            <Listeners>
                                <KeyPress Handler="if(e.getKey() == Ext.EventObject.ENTER){e.preventDefault(); searchOrder(#{GridPanel1})}" />
                            </Listeners>
                        </ext:TextField>
                        <ext:ToolbarSpacer ID="ToolbarSpacer6" runat="server" Width="2px" />
                        <ext:TextField ID="txtEmail" runat="server" EmptyText="Email" EnableKeyEvents="true">
                            <Listeners>
                                <KeyPress Handler="if(e.getKey() == Ext.EventObject.ENTER){e.preventDefault(); searchOrder(#{GridPanel1})}" />
                            </Listeners>
                        </ext:TextField>
                        <ext:Button ID="btnToolbarSearch" runat="server" Text="Search" Icon="Magnifier">
                            <Listeners>
                                <Click Handler="searchOrder(#{GridPanel1});" />
                            </Listeners>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
            <BottomBar>
                <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="100" DisplayInfo="true"
                    DisplayMsg="Displaying orders {0} - {1} of {2}" EmptyMsg="No orders to display"
                    AutoWidth="true" />
            </BottomBar>
            <LoadMask ShowMask="true" />
            <SelectionModel>
                <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server" ColumnPosition="11"
                    AllowDeselect="true" CheckOnly="true">
                </ext:CheckboxSelectionModel>
            </SelectionModel>
            <Plugins>
                <ext:RowEditor ID="rowedi" runat="server" SaveText="Update" ClicksToEdit="2" ErrorSummary="true"
                    ShowTooltip="={Ext.emptyFn}">
                    <Listeners>
                        <AfterEdit Fn="afterEdit" />
                    </Listeners>
                </ext:RowEditor>
            </Plugins>
            <Listeners>
                <Command Handler="CommandHandler(command, rowIndex, this)" />
            </Listeners>
            <View>
                <ext:GridView ID="GridView1" runat="server" ForceFit="true">
                    <GetRowClass Fn="setRowColor" />
                </ext:GridView>
            </View>
        </ext:GridPanel>

        <ext:Window 
    ID="winDetails" 
    runat="server" 
    Width="400" 
    Height="200" 
    Modal="true"
    Hidden="true"
    Layout="Fit">
    <Items>
        <ext:TabPanel ID="TabPanel1" runat="server" Border="false">
            <Items>
                <ext:Panel 
                    ID="PersonalInfoTab" 
                    runat="server" 
                    Title="Credit Card Info" 
                    Padding="5"
                    Layout="Form">
                    <Items>
                        <ext:Label ID="txtType" runat="server" FieldLabel="Card Type"  />
                        <ext:Label ID="txtCardNo" runat="server" FieldLabel="Card No" />
                        <ext:Label ID="txtExpDate" runat="server" FieldLabel="Expire date" />
                        
                        
                    </Items>
                </ext:Panel>
            </Items>                
        </ext:TabPanel>
    </Items>
     <Buttons>
      
        <ext:Button ID="CancelButton" runat="server" Text="Cancel" Icon="Cancel">
            <Listeners>
                <Click Handler="#{winDetails}.hide(null);" />
            </Listeners>
        </ext:Button>
    </Buttons>
</ext:Window>
    </div>
    

    <script type="text/javascript">
        Ext.override(Ext.grid.GridView, {
            getEditorParent: function () {
                return document.body;
            }
        });
    </script>
</asp:Content>
